function minimize(data:Object, context:Object):Object
{	
	var content:String="";

	content+="<moonlight name='BookCreation' template='BookCreation-relatedInfoContainer' uri='app/content/bookPage/BookCreation.xml'>";
	content+="<portlet name='"+context.portletName+"'><textfield name='bookNameRelatedHint' html='true' selectable='no' width='500'>"+context.portletName.toUpperCase()+"Hint</textfield>";
	content+="<portlet name='booksContainer' x='5' y='25' layout='area:125:495' >"

	for (var i=0; i<data.books.length; i++)
	{
		content+=getBookNameItem(data.books[i]);
	}

	content+="</portlet></portlet></moonlight>";

	var voData:Object=new Object();
	voData.content=content;
	voData.type="Template";

	// Packages.log("content: "+content, "debug");

	return voData;
}

function getBookNameItem(item:Object):String
{
	var cont:String;
	cont="<portlet name='bookItem_"+item.bookId+"' height='25' width='160'>";
	cont+="<textfield name='bookName_"+item.bookId+"' x='5' html='true' selectable='no' width='150' height='20'>"+item.name+"</textfield>";
	cont+="<handler ins='BookCreation-bookItem_"+item.bookId+"' type='onRollOver' src='lib:notes.system.events.StateFulButtonEvent.invokeRollOverEvent'/>";
	cont+="<handler ins='BookCreation-bookItem_"+item.bookId+"' type='onRollOut' src='lib:notes.system.events.StateFulButtonEvent.invokeRollOutEvent'/>";
	cont+="<handler ins='BookCreation-bookItem_"+item.bookId+"' type='onPress' src='lib:notes.system.events.StateFulButtonEvent.invokePressEvent'/>";
	cont+="<handler ins='BookCreation-bookItem_"+item.bookId+"' type='onRelease' src='lib:notes.system.events.StateFulButtonEvent.invokeReleaseEvent'/>";
	cont+="<handler ins='BookCreation-bookItem_"+item.bookId+"' type='onReleaseOutside' src='lib:notes.system.events.StateFulButtonEvent.invokeRollOutEvent'/>";
	cont+="</portlet>";

	return cont;
}

function getBookSummaryItem(item:Object, context:Object):String
{
	if (item.bookId==null || item.name==null) return "";

	var cont:String="";
	cont+="<portlet name='#hgap_"+item.bookId+"' width='10' height='110' curve='0' colorstart='0xffffff' colorend='0xffffff' alphastart='0' alphaend='0'/>";
	cont+="<portlet name='bookItem_"+item.bookId+"' height='100' width='300' >"
	cont+="<textfield name='header' bgcolor='0xffffff' width='240' html='true' x='28' y='-10' selectable='no' >"+item.name+"</textfield>";
	if (item.image!=null)
	{
		// cont+="<media name='bookCover_"+item.bookId+"' x='13' y='10' type='image' width='64' height='80' src='"+item.image+"'/>";
		cont+="<portlet name='bookCover_"+item.bookId+"' x='13' y='10' height='80' width='64' />"
	}
	else
	{
		//cont+="<portlet name='bookCover_"+item.bookId+"' x='10' y='7' linew='-1' curve='0' width='64' height='80'>";
		cont+="<textfield name='imageLabel_"+item.bookId+"' x='30' y='42' selectable='no' html='html' width='40'>CoverLabel</textfield>";
	}
	cont+="<textfield name='description' x='90' y='5' selectable='no' html='true' width='200' height='65'>"+item.abstract+"</textfield>";
	cont+="<textfield name='ratingHint' x='90' y='70' width='40' selectable='no' html='true'>BookRating</textfield>";
	cont+="<textfield name='rating' x='130' y='70' width='30' selectable='no' html='true'>"+(item.rating?item.rating:"")+"</textfield>";
	cont+="<textfield name='activeLevelHint' x='160' y='70' width='40' selectable='no' html='true'>BookActiveLevel</textfield>";
	cont+="<textfield name='activeLevel' x='200' y='70' width='30' selectable='no' html='true'>"+(item.activeLevel?item.activeLevel:"")+"</textfield>";
	cont+="<textfield name='completeStatusHint' x='230' y='70' width='40' selectable='no' html='true'>BookCompleteStatus</textfield>";
	cont+="<textfield name='completeStatus' x='270' y='70' width='30' selectable='no' html='true'>"+(item.completeStatus?item.completeStatus:"")+"</textfield>";
	cont+=addHandler(item, context);
	cont+="</portlet>";

	return cont;
}

function detail(data:Object, context:Object)
{
	var content:String="";

	content+="<moonlight name='"+context.slot+"' template='"+context.slot+"-"+context.container+"' uri='"+context.uri+"'>";
	// content+="<portlet name='booksContainer' x='0' y='0' layout='area:400:640' >";

	var dataCollection=data.books?data.books:data.objects;
	
	for (var i=0; i<dataCollection.length; i++)
	{
		content+=getBookSummaryItem(dataCollection[i], context);
	}
	
	// content+="<handler ins='BookList-booksContainer' type='onMLInit' value='BookList' src='lib:notes.components.content.bookPage.BookList.onBooksContainerInit'/>";
	// content+="</portlet></moonlight>";
	content+="<portlet name='#gap' width='620' height='10' curve='0' colorstart='0xfffff' colorend='0xffffff' alphastart='0' alphaend='0'><handler ins='"+context.slot+"-"+context.container+"' type='onMLInit' value='"+context.slot+"' src='"+context.initMethod+"'/></portlet>";
	content+="</moonlight>";

	var voData:Object=new Object();
	voData.content=content;
	voData.type="Template";

	// Packages.log("content: "+content, "debug");

	return voData;
}

function getBookCoverItem(item:Object, context:Object):String
{
	if (item.bookId==null || item.name==null) return "";

	var cont:String="";
	cont+="<portlet name='#hgap_"+item.bookId+"_"+context.container+"' width='3' height='100' curve='0' colorstart='0xffffff' colorend='0xffffff' alphastart='0' alphaend='0'/>";
	cont+="<portlet name='bookItem_"+item.bookId+"_"+context.container+"' height='90' width='72' >";
	// else 
	
	cont+=addHandler(item, context);
	cont+="</portlet>";

	return cont;
}

function getBookBasicItem(item:Object, context:Object):String
{
	if (item.bookId==null || item.name==null) return "";

	var cont:String="";
	cont+="<portlet name='#hgap_"+item.bookId+"_"+context.container+"' width='3' height='140' curve='0' colorstart='0xffffff' colorend='0xffffff' alphastart='0' alphaend='0'/>";
	cont+="<portlet name='bookItem_"+item.bookId+"_"+context.container+"' height='130' width='88' >";
	cont+="<textfield name='bookName_"+item.bookId+"' html='true' width='88' y='110' x='-3'><p align='center'>"+item.name+"</p></textfield>";
	// else 
	
	cont+=addHandler(item, context);
	cont+="</portlet>";

	return cont;
}

function normal(data:Object, context:Object)
{
	var content:String="";

	content+="<moonlight name='"+context.slot+"' template='"+context.slot+"-"+context.container+"' uri='"+context.uri+"'>";

	// var dataCollection=data.books?data.books:data.objects;
	var dataCollection=data.books;
	dataCollection.reverse();
	
	for (var i=0; i<dataCollection.length; i++)
	{
		content+=getBookCoverItem(dataCollection[i], context);
	}
	
	content+="<portlet name='@handler_"+context.container+"' x='150' y='190'><textfield name='moreOperLabel_"+context.container+"' html='true' width='80'>MoreOperLabel</textfield><hotspot name='moreSpot_"+context.container+"' width='60' height='20' alpha='0' /><handler ins='"+context.slot+"-"+context.container+"' type='onMLInit' value='"+context.slot+"' src='"+context.initMethod+"'/></portlet>";
	content+="</moonlight>";

	var voData:Object=new Object();
	voData.content=content;
	voData.type="Template";

	// Packages.log("content: "+voData.content, "debug");

	return voData;
}

function expand(data:Object, context:Object)
{
	var content:String="";

	content+="<moonlight name='"+context.slot+"' template='"+context.slot+"-"+context.container+"' uri='"+context.uri+"'>";

	// var dataCollection=data.books?data.books:data.objects;
	var dataCollection=data.books;
	dataCollection.reverse();
	
	for (var i=0; i<dataCollection.length; i++)
	{
		content+=getBookBasicItem(dataCollection[i], context);
	}
	
	content+="<portlet name='@handler_"+context.container+"' x='260' y='30'><handler ins='"+context.slot+"-"+context.container+"' type='onMLInit' value='"+context.slot+"' src='"+context.initMethod+"'/>";
	content+=addPageSection(context);
	content+="</portlet></moonlight>";

	var voData:Object=new Object();
	voData.content=content;
	voData.type="Template";

	// Packages.log("content: "+voData.content, "debug");

	return voData;
}

function addHandler(item:Object, context:Object):String
{
	var src:String="";

	src+="<handler ins='"+context.slot+"-bookItem_"+item.bookId+"_"+context.container+"' type='onRollOver' src='lib:notes.system.events.StateFulButtonEvent.invokeRollOverEvent'/>";
	src+="<handler ins='"+context.slot+"-bookItem_"+item.bookId+"_"+context.container+"' type='onRollOut' src='lib:notes.system.events.StateFulButtonEvent.invokeRollOutEvent'/>";
	src+="<handler ins='"+context.slot+"-bookItem_"+item.bookId+"_"+context.container+"' type='onPress' src='lib:notes.system.events.StateFulButtonEvent.invokePressEvent'/>";
	src+="<handler ins='"+context.slot+"-bookItem_"+item.bookId+"_"+context.container+"' type='onRelease' src='lib:notes.system.events.StateFulButtonEvent.invokeReleaseEvent'/>";
	src+="<handler ins='"+context.slot+"-bookItem_"+item.bookId+"_"+context.container+"' type='onReleaseOutside' src='lib:notes.system.events.StateFulButtonEvent.invokeRollOutEvent'/>";

	return src;
}

function addPageSection(context):String
{
	var cont:String="";
	cont+="<textfield name='bookListPreLabel' x='20' y='405' width='50' selectable='no' html='true'>BookListPreLabel</textfield>";
	cont+="<hotspot name='bookListPreSpot' x='20' y='405' alpha='0' width='50' height='20'/>";
	cont+="<textfield name='bookListCurrentPage' type='input' x='65' y='405' width='25'>1</textfield>";
	cont+="<textfield name='bookListSlash' x='95' y='405' width='10' selectable='no' html='true'>/</textfield>";
	cont+="<textfield name='bookListTotalPage' x='105' y='405' width='25' selectable='no' html='true'>1</textfield>";
	cont+="<textfield name='bookListNextLabel' x='130' y='405' width='50' selectable='no' html='true'>BookListNextLabel</textfield>";
	cont+="<hotspot name='bookListNextSpot' x='130' y='405' alpha='0' width='50' height='20'/>";
	cont+="<handler ins='"+context.slot+"-"+context.container+"' type='onKeyUp' value='13' src='"+context.enterEvent+"'><arg name='"+context.slot+"-"+context.container+"' as='pageNum'/></handler>";
	
	return cont;
}